<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <script src="../build/react.development.js"></script>
    <script src="../build/react-dom.development.js"></script>
    <script src="../build/babel.min.js"></script>
    <script src="../build/jquery.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    
    <!-- 这里babel标签,在解析时会对其进行编译转化 -->
    <script type="text/babel">
      class UserGist extends React.Component {
        constructor(props) {
          super(props)
          this.state = {
            username: '',
            lastGistUrl: ''
          }
        }

        // 使用jquery的ajax get组件

        
        componentDidMount() {
          $.get(this.props.dataline, ((result)=>{
            var lastGist = result[0];

            this.setState({
              username: lastGist.owner.login,
              lastGistUrl: lastGist.html_url
            });

          }) // 这里注意ES6的写法.bind函数得要在签名的回调用小括号包裹
          .bind(this));
        }

        render() {
          return (
            <div>
              {this.state.username}'s last gist is <a href={this.state.lastGistUrl}>here</a>.
            </div>
          );
        }
      }

      ReactDOM.render(
        <UserGist dataline="https://api.github.com/users/octocat/gists" />,
        document.getElementById('example')
      );
    </script>
  </body>
</html>
